package com.yk.anima.controller;

import com.yk.anima.api.ProductsDirdsApi;
import com.yk.anima.pojo.ProductsDirds;
import com.yk.anima.response.QueryResponseResult;
import com.yk.anima.response.ResponseResult;
import com.yk.anima.servlet.ProductsDirdsServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaokai
 * @create 2021-05-13 22:27:51
 * @desc... 对鸟类进行增删改查
 */
@RestController
@RequestMapping("/dirds")
public class ProductsDirdsController implements ProductsDirdsApi {

    @Autowired
    ProductsDirdsServlet productsDirdsServlet;

    /**
     * @param
     * @return java.util.List<com.yk.anima.pojo.ProductsDirds>
     * @Author xiaoKai
     * @Description 查询所有鸟类
     * @Date 19:18 2021/5/14
     */
    @Override
    @GetMapping("/findAll")
    public List<ProductsDirds> findAll() {
        return productsDirdsServlet.findAll();
    }

    /**
     * @param id
     * @return com.yk.anima.pojo.ProductsDirds
     * @Author xiaoKai
     * @Description 根据ID查询鸟类
     * @Date 19:20 2021/5/14
     */
    @Override
    @GetMapping("/findById/{id}")
    public ProductsDirds findById(@PathVariable("id") int id) {
        return productsDirdsServlet.findById(id);
    }

    /**
     * @param id
     * @param productsDirds
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description
     * @Date 19:21 2021/5/14
     */
    @Override
    @PutMapping("/update/{id}")
    public ResponseResult update(@PathVariable("id") int id, @RequestBody ProductsDirds productsDirds) {
        return productsDirdsServlet.update(id, productsDirds);
    }

    /**
     * @param productsDirds
     * @return com.yk.anima.response.ResponseResult
     * @Author xiaoKai
     * @Description添加鸟类
     * @Date 19:52 2021/5/14
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ProductsDirds productsDirds) {
        return productsDirdsServlet.save(productsDirds);
    }

    /**
     * @Author xiaoKai
     * @Description 根据Id删除
     * @Date 20:03 2021/5/14
     * @param id
     * @return com.yk.anima.response.ResponseResult
     */
    @Override
    @DeleteMapping("/deleteById/{id}")
    public ResponseResult deleteById(@PathVariable("id") int id) {
        return productsDirdsServlet.deleteById(id);
    }

    /**
     * @Author xiaoKai
     * @Description 分页查询
     * @Date 22:30 2021/5/14
     * @param page 
	 * @param size 
	 * @param name 
     * @return com.yk.anima.response.QueryResponseResult
     */
    @Override
    @GetMapping("/findByPage/{page}/{size}")
    public QueryResponseResult findByPage( @PathVariable("page") int page,
                                           @PathVariable("size") int size,String name) {

        return productsDirdsServlet.findByPage(size,page,name);
    }
}
